package com.gopay.common.oldmermove.dao.impl;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.constants.oldmermove.OldMerTranEffectStatus;
import com.gopay.common.constants.oldmermove.OldMerTranOpenStatus;
import com.gopay.common.domain.oldmermove.OldMovedMerOpenTran;
import com.gopay.common.domain.oldmermove.OldMovedMerOpenTranId;
import com.gopay.common.oldmermove.dao.OldMovedMerOpenTranDAO;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;

/**
 * 老平台迁移商户开通交易记录
 * 
 * @OldMovedMerOpenTranDAOImpl.java
 * @author lizheng
 * @2014-7-3 下午4:25:18 www.gopay.com.cn Inc.All rights reserved.
 */
@Repository("oldMovedMerOpenTranDAO")
public class OldMovedMerOpenTranDAOImpl extends BaseDAOImpl<OldMovedMerOpenTran, Serializable> implements
		OldMovedMerOpenTranDAO {

	/**
	 * 根据商户ID、交易码查询对象
	 */
	@Override
	public OldMovedMerOpenTran getByOldMerIdAndTranCode(String merId, String tranCode) {
		return this.find(OldMovedMerOpenTran.class, new OldMovedMerOpenTranId(merId, tranCode));
	}
	
	/**
	 * 查询所有设置的生效时间小于当期时间的记录
	 */
	@Override
	public List<OldMovedMerOpenTran> findSetupEffectTimeLessNow() {
		DetachedCriteria criteria = DetachedCriteria.forClass(OldMovedMerOpenTran.class);
		// 查询条件：已开通、已设置生效时间、设定的开通时间<=当前时间
		criteria.add(Restrictions.eq("openStatus", OldMerTranOpenStatus.SUCC));
		criteria.add(Restrictions.eq("effectStatus", OldMerTranEffectStatus.HAVE_SET));
		criteria.add(Restrictions.le("setupEffectTs", new Timestamp(System.currentTimeMillis())));

		return this.findByCriteria(criteria);
	}
}
